package com.songyl.message.dao;

import com.songyl.message.entity.Message;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Component;

import javax.transaction.Transactional;
import java.util.List;

/**
 * 用户服务数据接口类
 *
 * @author SYL
 * @since 2018-03-12
 */

@Component("MessageDao")
@Transactional
public interface MessageDao extends JpaRepository<Message, Long> {
    /**
     * @return
     */
    @Query(value = "select  u from Message u  where u.flag=0 "
            + "order by u.createTime desc")
    List<Message> getAllByCreateTime();


    /**
     * @param ids
     */
    @Modifying
    @Query(value = "update Message u set u.flag = 1 where u.id in(:ids) ")
    int deleteInBatchById (@Param("ids")  List<Long> ids);
}